#ifndef INCLUDED_ENGINE_REPOSITORY_H
#define INCLUDED_ENGINE_REPOSITORY_H

//====================================================================================================
// Filename:	Repository.h
// Created by:	Josh Blidook
//====================================================================================================

// Code from Slant 6, Peter thinks it might not be that good...

//====================================================================================================
// Includes
//====================================================================================================

#include "ID.h"

//====================================================================================================
// Class Declarations
//====================================================================================================

class RepositoryBase // Used to store only one Type, it is privated
{
public:
	RepositoryBase(Meta::Type type)
		: mType(type)
	{
	}

	//~RepositoryBase();

	Meta::Type GetType() const { return mType; }

private:
	Meta::Type mType;
};

//----------------------------------------------------------------------------------------------------

template <typename T>
class Repository : public RepositoryBase // Used to store only one Type, it is privated
{
public:
	Repository(Meta::Type _type, u16 capacity);

	ID Allocate();
	void Free(ID& id);

	T& GetItem(ID id); // Assumes this exists, Would call an ASSERT if this does not exist
	const T& GetItem(ID id) const;

	T* FindItem(ID id); // Returns pointer
	const T* FindItem(ID id) const;

private:
	bool IsValid(ID id) const;

	std::vector<T> mData; // No gaps up to end, need to presurve these though
	std::vector<u8> mInstanceCount;
	std::vector<u16> mFreeSlots; // Put in list when taken out mid way in mData
};

//----------------------------------------------------------------------------------------------------

//====================================================================================================
// Inline Declarations
//====================================================================================================

#include "Repository.inl"

#endif // #ifndef INCLUDED_ENGINE_REPOSITORY_H